package com.lai.entities;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Entity
@Table(name="sec_users")
public class User implements UserDetails {

    @Id
    private int id;
    @Column
    private String name;
    @Column
    private String password;
    @Column
    private boolean disabled;

    public User() {
    }

    public User(String name, String pwd) {
        this.name = name;
        this.password = pwd;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        GrantedAuthority tt = new SimpleGrantedAuthority("ROLE_USER");
        List gg = new ArrayList();
        gg.add(tt);
        return gg;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return this.name;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isEnabled() {
        return !this.disabled;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
